package com.hymandev.goodadpter;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.hymandev.goodadpter.adapter.MyAdapter;
import com.hymandev.goodadpter.bean.Book;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ListView lv_books;
    private MyAdapter mAdapter;
    private List<Book> books;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }


    private void initView() {
        lv_books = (ListView) findViewById(R.id.lv_books);
    }

    private void initData() {
        books = new ArrayList<Book>();
        for (int i = 0; i < 20; i++) {
            Book book = new Book();
            book.setTitle("编程图书" + i);
            book.setTitle("这是一本比较牛逼的编程图书" + i);
            book.setPrice((int) (18.35 * i / 4) + "");
            books.add(book);
        }
        mAdapter = new MyAdapter(this, books);
        lv_books.setAdapter(mAdapter);
    }
}
